package listados;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.io.File;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import paneles.JPanelConFondo;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterException;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PaneListados extends JPanel{
	private JScrollPane jScrollPane1;
	private JButton jButton1;
	private JTable jTable1;
	private Vector titulo;
	private JButton btnNewButton;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		
		JFrame frame = new JFrame();
		Vector v=new Vector();
		v.add("hola");
		frame.getContentPane().add(new PaneListados(v));
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	@SuppressWarnings("unchecked")
	public PaneListados(Vector titulos) {
		super();
		this.titulo=titulos;
		initGUI();

	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(474, 350));
			FlowLayout thisLayout = new FlowLayout();
			thisLayout.setVgap(10);
			this.setLayout(thisLayout);
			{
				jButton1 = new JButton();
				this.add(jButton1);
				jButton1.setText("Mostrar Resultados");
				jButton1.setPreferredSize(new java.awt.Dimension(167, 25));
			}
			{
				jScrollPane1 = new JScrollPane();
				this.add(jScrollPane1);
				jScrollPane1.setPreferredSize(new java.awt.Dimension(540, 260));
				jScrollPane1.setAutoscrolls(true);
				jScrollPane1.setFont(new java.awt.Font("Dialog",1,12));
				jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

				{
					TableModel jTable1Model = 
						new DefaultTableModel(
								new String[][] {},
								this.titulo.toArray());
					jTable1 = new JTable(jTable1Model);
					jTable1.setRowHeight(20);
					jTable1.setPreferredSize(new java.awt.Dimension(497, 350));
					jScrollPane1.setViewportView(jTable1);
				}
				jScrollPane1.setViewportView(jTable1);
				jTable1.setFont(new java.awt.Font("Arial",1,12));
			}
			{
				btnNewButton = new JButton("Imprimir");
				btnNewButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						try {
							PaneListados.this.jTable1.print();
						} catch (PrinterException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
				add(btnNewButton);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public JTable getJTable1() {
		return jTable1;
	}

	public void setJTable1(JTable table1) {
		jTable1 = table1;
	}

	public JButton getJButton1() {
		return jButton1;
	}

	public void borrarTabla() {
		int n = getJTable1().getRowCount();
		for (int i=1; i<n+1; i++)
			((DefaultTableModel) jTable1.getModel()).removeRow(n-i);
		this.setPreferredSize(new java.awt.Dimension(550, 310));
		jTable1.updateUI();
	}

	public JScrollPane getJScrollPane1() {
		return jScrollPane1;
	}



}
